package April._25.homework.work5;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;
import java.util.concurrent.Callable;

public class reciveTask implements Runnable {
    Socket socket;

    public reciveTask(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        InputStream inputStream = null;
        boolean flag=true;
        while (flag){
            String msg=null;
            try {
                //获取输入流socket
                inputStream = socket.getInputStream();
                //转换为字符流
                InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                //读取消息
                char[] chars = new char[1024];
                int read = inputStreamReader.read(chars);
                msg=new String(chars,0,read);
                System.out.println("msg = " + msg);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }

    /*@Override
    public String call() throws Exception {
        InputStream inputStream = null;
        boolean flag=true;

        while (flag){
            String msg=null;
            try {
                //获取输入流socket
                inputStream = socket.getInputStream();
                //转换为字符流
                InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                //读取消息
                char[] chars = new char[1024];
                int read = inputStreamReader.read(chars);
                msg=new String(chars,0,read);
                System.out.println("msg = " + msg);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return ;
    }*/

    /*@Override
    public void run() {
        InputStream inputStream = null;
        boolean flag=true;
        while (flag){
            try {
                //获取输入流socket
                inputStream = socket.getInputStream();
                //转换为字符流
                InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                //读取消息
                char[] chars = new char[1024];
                int read = inputStreamReader.read(chars);
                //
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }


    }*/


}
